package com.zing.network.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zing.network.R;
import com.zing.network.net.ProjectBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author jichang
 * @date 2018/9/19 21:59
 * email: 2218982471@qq.com
 * describ:
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    private ProjectBean.DataBean data;

    private Context mContext;

    public MyAdapter(ProjectBean.DataBean data) {
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new ViewHolder(LayoutInflater
                .from(parent.getContext())
                .inflate(R.layout.item_project_list, null));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ProjectBean.DataBean.DatasBean da = data.getDatas().get(position);
        Glide.with(mContext).load(da.getEnvelopePic()).into(holder.img);
        holder.title.setText(da.getTitle());
        holder.content.setText(da.getDesc());
        holder.time.setText(da.getNiceDate());
        holder.author.setText(da.getAuthor());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.getSize();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.image_simple)
        ImageView img;
        @BindView(R.id.tv_title)
        TextView title;
        @BindView(R.id.tv_content)
        TextView content;
        @BindView(R.id.tv_time)
        TextView time;
        @BindView(R.id.tv_author)
        TextView author;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
